// unknow 是any的安全类型
//unknown和any对比学习
//any我们可以对any进行任何操作，而不需要检查类型
let value:any;
value = true
value = 1

value.foo()

//unknown 不知道类型 
//任何类型都可以赋值给unknown
let value2:unknown
value2 = true
value2 = 1
value2 = []

//value2.foo();
//如果想调用unknown上的方法和属性 
value2 = 'hello'
//断言
console.log((value2 as string).length)
//typeof
if(typeof value2 == 'string'){
    console.log(value2.length)
}

//联合类型中的unknown:不管和谁联合，最后都是unknown
type U1 = unknown|null
type U2 = unknown |undefined
type U3 = unknown|string
type U4 =unknown |number[]

//交叉类型：要满足双方的条件
interface A{name:string}
interface B{age:number}
type C = A&B
//是A的子类型 也是B的子类型
let c:C = {name:'xx',age:10}

type AA = string|number
type BB = string|boolean
//type CC = AA&&BB


//never是unknown的子类型
type isNever = never extends unknown?true:false
type keys = keyof unknown

let aa:unknown
let bb:unknown
console.log(aa===bb);
console.log(aa!==bb);

//映射属性的时候
//如果映射类型是unknown 不会映射属性
type getType<T> = {
    [p in keyof T]:number
}
type t = getType<unknown> //{}
